#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        if(matrix.empty()){
            return;
        }
        int i = 0;
        int j = matrix[0].size()-1;
        
        while(i<matrix.size()&&j>=0){
            for(int t = 0;t<matrix.size();t++){
               
                if( &matrix[i][t] !=  &matrix[matrix.size()-1-t][j]){
                    int temp = matrix[i][t];
                    matrix[i][t] = matrix[matrix.size()-1-t][j];
                    matrix[matrix.size()-1-t][j] = temp;

                }
                else{
                    break;
                }

            }
            i = i+1;
            j = j-1;
        }
        //再将其上下翻转
        
        int h = 0;
        while(h<((matrix.size()/2))){
            for(int l = 0;l<matrix.size();l++){
                int temp = matrix[h][l];
                matrix[h][l] = matrix[matrix.size()-1-h][l];
                matrix[matrix.size()-1-h][l] = temp;
            }
            h = h+1;
        }
    }
};

int main(){
    vector<vector<int>> V = {{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
    Solution S;
    S.rotate(V);
    return 0;
}